<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.math.BigDecimal"%>
<%@ page import="lib.db.admin.*"%>
<jsp:useBean id="bdAdminDAO" class="lib.db.admin.AdminDAO" scope="session"/>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK href="../include/default.css" type="text/css" rel="stylesheet">
<SCRIPT src="../include/default.js" type="text/javascript"></SCRIPT>
<title>ADMIN:EDIT</title>
</head>

<body>
<%@ include file="../include/header.jsp" %>
<br>

<%
    String sAdminId = request.getParameter("id");
    if(sAdminId != null || !"".equals(sAdminId)) {
        long currRight = 0;
        String currIP  = null;
        String sAction = request.getParameter("Action");
        if (sAction == null || !"UPDATE".equals(sAction)) {
        Admin admin = bdAdminDAO.getRow(new BigDecimal(sAdminId));
            if (admin != null) {
                currRight = admin.getRight();
                currIP    = admin.getIPAddress();
                if (currIP == null) currIP = "";
            }
        } else { //update new right
            long newRight = 0;
            if (request.getParameter("chkCreate") != null) //checked
            	newRight = newRight | AdminRights.ADM_RIGHT_CORE_CREATE;
            if (request.getParameter("chkDelete") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_CORE_DELETE;
            if (request.getParameter("chkUpdate") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_CORE_UPDATE;
            if (request.getParameter("chkSelect") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_CORE_SELECT;

            if (request.getParameter("chkGeneral") != null)
                    newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_GENERAL;
            if (request.getParameter("chkChampion") != null)
                    newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_CHAMPION;
            if (request.getParameter("chkMatchEdit") != null)
                    newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_EDIT;
            if (request.getParameter("chkMatchSelect") != null)
                    newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_SELECT;
	    	if (request.getParameter("chkInvalid") != null)
                    newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_INVALID;

            if (request.getParameter("chkDaily") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_DAILY;
            if (request.getParameter("chkTip") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_TIP;
            if (request.getParameter("chkWait") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_WAIT;
            if (request.getParameter("chkTuongthuat") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_TUONGTHUAT;
            if (request.getParameter("chkConvert") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_CONVERT;

	    	if (request.getParameter("chkAccount") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_ACCOUNT;
			
	    	if (request.getParameter("chkCtv") != null)
                newRight = newRight | AdminRights.ADM_RIGHT_PATH_FOOTBALL_CTV;
			
            String newIP = request.getParameter("txtIP");
            ////////////////////////////////////////////////////////////////////
            boolean success = bdAdminDAO.updateRight(new BigDecimal(sAdminId), newRight, newIP);
            ////////////////////////////////////////////////////////////////////
            if (success) {
                currRight = newRight;
                currIP    = newIP;
            }
        }
%>


<p align="center">
<b><font color="#000080" face="Tahoma" size="4">
DANH SÁCH CÁC QUYỀN
</font></b>
</p>


<FORM NAME="frmAdd" METHOD="POST">
<div align="center">
<table border="1" width="350" cellspacing="0" bordercolor="#008080" style="border-collapse: collapse" cellpadding="4">
  <tr>
    <td width="350" align="left" bgcolor="#FFFFF8" colspan=2>
        <font face="Verdana, Tahoma" size="2" color="#000080"><b>
        Quyền cơ bản:</b></font>
  </tr>
  <tr>
    <td width="30" align="right" bgcolor="#FFFFF8">
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8">
        <font face="Verdana, Tahoma" size="2" color="#000080">
        <input type="checkbox" name="chkCreate" <%if ((currRight & AdminRights.ADM_RIGHT_CORE_CREATE) == AdminRights.ADM_RIGHT_CORE_CREATE) out.println("checked");%>> Tạo &nbsp;
        <input type="checkbox" name="chkDelete" <%if ((currRight & AdminRights.ADM_RIGHT_CORE_DELETE) == AdminRights.ADM_RIGHT_CORE_DELETE) out.println("checked");%>> Xoá &nbsp;
        <input type="checkbox" name="chkUpdate" <%if ((currRight & AdminRights.ADM_RIGHT_CORE_UPDATE) == AdminRights.ADM_RIGHT_CORE_UPDATE) out.println("checked");%>> Sửa &nbsp;
        <input type="checkbox" name="chkSelect" <%if ((currRight & AdminRights.ADM_RIGHT_CORE_SELECT) == AdminRights.ADM_RIGHT_CORE_SELECT) out.println("checked");%>> Xem &nbsp;
	</font>
  </tr>

  <tr>
    <td width="350" align="left" bgcolor="#FFFFF8" colspan=2><br>
        <font face="Verdana, Tahoma" size="2" color="#000080"><b>
        Quyền thao tác trên các nội dung: </b></font>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
    	<input type="checkbox" name="chkGeneral" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_GENERAL) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_GENERAL) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Mục thông tin chung
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkChampion" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_CHAMPION) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_CHAMPION) out.println("checked");%>>
    </td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Mùa giải / giải đấu / đội bóng / bxh
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkMatchEdit" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_EDIT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_EDIT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Thêm / sửa trận đấu
    </td>
  </tr>

  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkMatchSelect" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_SELECT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_MATCH_SELECT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Chọn trận đấu vào KQ
    </td>
  </tr>

  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkInvalid" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_INVALID) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_INVALID) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Trả lời Invalid
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkDaily" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_DAILY) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_DAILY) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Info daily
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkTip" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_TIP) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_TIP) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        TIP / TẢI / XỈU
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkWait" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_WAIT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_WAIT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Đăng ký 85,87
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	<input type="checkbox" name="chkTuongthuat" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_TUONGTHUAT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_TUONGTHUAT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Tường thuật
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
    	<input type="checkbox" name="chkConvert" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_CONVERT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_CONVERT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8" class="list">
        Chuyển đổi mã
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#EEEEEE">
	<input type="checkbox" name="chkCtv" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_CTV) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_CTV) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#EEEEEE" class="list">
        Cộng tác viên Tường thuật
    </td>
  </tr>
  <tr>
    <td width="30" align="center" bgcolor="#EEEEEE">
	<input type="checkbox" name="chkAccount" <%if ((currRight & AdminRights.ADM_RIGHT_PATH_FOOTBALL_ACCOUNT) == AdminRights.ADM_RIGHT_PATH_FOOTBALL_ACCOUNT) out.println("checked");%>>
	</td>
    <td width="320" align="left" bgcolor="#EEEEEE" class="list">
        Quản lý account admin
    </td>
  </tr>

  <tr>
    <td width="30" align="center" bgcolor="#FFFFF8">
	</td>
    <td width="320" align="left" bgcolor="#FFFFF8">
	<font face="Verdana, Tahoma" size="1" color="#000080">
        IP Address (By default, user can access from any IP): </font>
	<textarea name="txtIP" cols="35" rows="3" class="flatinput"><%=currIP%></textarea>
  </tr>

  <tr>
    <td width="30" align="right" bgcolor="#FFFFF8">
	<a href="list.jsp"> <img src="../images/quote.gif" border=0> </a>
    </td>
    <td width="320" align="left" bgcolor="#FFFFF8">
        <input type="submit" value=" Update " name="butUpdate" class="flatbutton">
        <input type="reset" value=" Reset " name="butReset" class="flatbutton">
        <input type="hidden" name="Action" value="UPDATE">
	<input type="hidden" name="id" value="<%=sAdminId%>">
    </td>
  </tr>
</table>
</div>
</FORM>
<%
    }
%>
</body>
</html>
